<?php

/**
 * @author Martin Pernica
 * @copyright 2008
 */
 echo '<br /><h2><a href="index.php?p=components&name=custom">Zpět</a></h2><br />';
if(!empty($_POST['title']) && !empty($_POST['page_content'])){
	$title = Registry::get('db')->real_escape_string(strip_tags($_POST['title']));
	$content = Registry::get('db')->real_escape_string($_POST['page_content']);
	$require_rank = intval($_POST['require_rank']);

	$query = $GLOBALS['db']->query("INSERT INTO {prefix}custom (title, content, require_rank) VALUES('".$title."', '".$content."', '".$require_rank."')") or die($GLOBALS['db']->error);
	unset($query);
	$query = $GLOBALS['db']->query("SELECT last_insert_id() as id FROM {prefix}custom");
	$last_id = $query->fetch_array();
	$seoParser = new SeoUrl();
	$seoParser->Parse($title);
 	$seo_url = $last_id['id'] . "-" . $seoParser->result;
  	$log->write(8, 'com_custom', 'NOW()', 'User created new page', User::getUid());
	
    messageBox( Lang::getBack('com_custom', 'added_done') );
    
	echo '<p class="msg info">'.Lang::getBack('com_custom', 'menu_link').' : <strong>index.php?q=custom/'.$seo_url.'</strong></p>';

}

$form = new Form;
$form->addTextbox('title', Lang::getBack('com_custom', 'title'), stripslashes($data['title']));
$form->addTextarea('page_content', Lang::getBack('com_custom', 'content'), stripslashes($data['content']), 30, 80, 'wysiwyg');
$form->addSelect('require_rank', Lang::getBack('com_custom', 'permissions'), $ranks, $data['require_rank']);
$form->addSubmit('submit_edit', Lang::getBackGlobal('submit'));

echo $form;

?>